# Contributor: Mehdi Chinoune <mehdi.chinoune@hotmail.com>

_realname=qt5-translations
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=5.15.17
pkgrel=1
pkgdesc="A cross-platform application and UI framework (Translations) (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.qt.io/'
msys2_references=(
  "cpe: cpe:/a:qt:qt"
)
license=('spdx:LGPL-3.0-only WITH Qt-GPL-exception-1.0')
depends=("${MINGW_PACKAGE_PREFIX}-qt5-base")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-qt5-tools")
groups=("${MINGW_PACKAGE_PREFIX}-qt5")
_pkgfn="${_realname/5-/}-everywhere-opensource-src-${pkgver}"
source=("https://download.qt.io/official_releases/qt/${pkgver%.*}/$pkgver/submodules/$_pkgfn.tar.xz")
sha256sums=('793ad3c8b40e99fac2b6c377f1145b8b280b22a6f78a35abe3b1b8f5cd4002fe')

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  qmake ../${_pkgfn/opensource-/}

  make
}

check() {
  cd build-${MSYSTEM}
  make check -j1 -k
}

package() {
  cd build-${MSYSTEM}

  # Fix Makefiles
  local PREFIX_WIN=$(cygpath -am ${MINGW_PREFIX})
  find "${srcdir}/build-${MSYSTEM}" -type f \( -name 'Makefile*' \) \
      -exec sed -i -e "s|${PREFIX_WIN:0:2}\$(INSTALL_ROOT|\$(INSTALL_ROOT|g" {} \;
  find "${srcdir}/build-${MSYSTEM}" -type f \( -name 'Makefile*' \) \
      -exec sed -i -e "s|)${PREFIX_WIN:2}|)${MINGW_PREFIX}|g" {} \;

  make INSTALL_ROOT="${pkgdir}" install

  install -d "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
  install -Dm644 $srcdir/${_pkgfn/opensource-/}/LICENSE* -t "$pkgdir${MINGW_PREFIX}"/share/licenses/${_realname}
}
